import numpy as np
def integral_im(noVocab,im):
    iiList = []
    for i in range(noVocab):
        ii = (im==i).astype('int').cumsum(1).cumsum(0)
        iiList.append(ii)
    return iiList


def detector():
    imBow = np.array([[5,2,3,4,1],[1,5,4,2,3],[2,2,1,3,4],[3,5,6,4,5],[4,1,3,2,6]])
    noVocab = 7
    iiList = integral_bow(noVocab,imBow)
    loc = (1,1)
    siz = (3,3)
    hist = []
    for ii in iiList:
        a = ii[loc[0]-1,loc[1]-1]
        b = ii[loc[0]+siz[0]-1,loc[1]-1]
        c = ii[loc[0]-1,loc[1]+siz[1]-1]
        d = ii[loc[0]+siz[0]-1,loc[1]+siz[1]-1]
        hist.append(d+a-b-c)
    return hist,iiList,a,b,c,d
